package cn.fzkj.framework.messagequece.service;

import cn.fzkj.framework.mail.MailEntity;
import com.google.gson.Gson;
import cn.fzkj.framework.messagequece.MessageInfo;
import cn.fzkj.framework.messagequece.MessageType;
import cn.fzkj.framework.messagequece.config.RabbitProducer;
import cn.fzkj.framework.web.domain.ResultVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/** 处理rabbitmq消息. */
@Component
public class MessageService {

    @Autowired
    private RabbitProducer rabbitProducer;

    /** 处理一般消息 */
    public ResultVO sendMess2Client(String content){
        return ResultVO.success();
    }

    /** 给redis发消息. */
    public ResultVO sendMsg2Redis(MessageType messageType, String content){
        MessageInfo messageInfo = new MessageInfo();
        messageInfo.setContent(content);
        messageInfo.setCreateTime(System.currentTimeMillis());
        messageInfo.setReceiveID("");
        messageInfo.setMessageType(messageType);
        rabbitProducer.tellRedisToGetImgOrWords(new Gson().toJson(messageInfo));
        return ResultVO.success();
    }

    /**
     * 处理普通邮件请求
     * @param content 邮件内容
     * @return
     */
    public ResultVO sendMailSimple(String content){
        MessageInfo info = new MessageInfo();
        info.setMessageType(MessageType.MAIL_SIMPLE);
        info.setContent(content);
        info.setCreateTime(System.currentTimeMillis());
        rabbitProducer.sendMail(new Gson().toJson(info));
        return ResultVO.success();
    }

    /**
     * 发送带附件邮件
     * @param content
     * @return
     */
    public ResultVO sendMailMime(String content){
        MessageInfo info = new MessageInfo();
        info.setMessageType(MessageType.MAIL_MIME);
        info.setContent(content);
        info.setCreateTime(System.currentTimeMillis());
        rabbitProducer.sendMail(new Gson().toJson(info));
        return ResultVO.success();
    }
}
